﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using HospitalSystem.Core;
namespace HospitalSystem
{
    public partial class FamilyDetails : System.Web.UI.Page
    {
        private show_Image _showimage;
        protected void Page_Load(object sender, EventArgs e)
        {
            showsession();
            _showimage = new show_Image();
          
            _showimage.show_Images(cid_label, Image1);
            
            showlistfamily2();
        }


        protected void showsession()
        {
            String ShowValue = (string)Session["CID"];
            cid_label.Text = ShowValue;
            String ShowValue2 = (string)Session["LastName"];
            lname.Text = ShowValue2;

            String ShowValue3 = (string)Session["FirstName"];
            fname.Text = ShowValue3;

        }

        public void showlistfamily2()
        {
            
            string fCIDstring = Request.QueryString["fCID"];
            string CIDstring = Request.QueryString["CID"];
            if (CIDstring != null && fCIDstring != null)
            {
                string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection scon = new SqlConnection(constr);
                SqlCommand cmd = new SqlCommand("SELECT a.Name as Name,a.LastName as LastName,a.fCID as fCID,a.LiveStatus as LiveStatus,a.Nation as Nation,a.Race as Race,a.Religion as Religion,a.LiveHouseNumber as LiveHouseNumber,a.LiveHouseName as LiveHouseName,a.LiveHouseMoo as LiveHouseMoo,a.LiveHousesoy as LiveHousesoy,a.LiveStreetName as LiveStreetName,a.Livetambon as Livetambon,a.LiveCity as LiveCity,a.LiveProvince as LiveProvince,a.LivePostcode as LivePostcode,a.CensusHouseNumber as CensusHouseNumber,a.CensusHouseName as CensusHouseName,a.CensusHouseMoo as CensusHouseMoo,a.CensusHousesoy as CensusHousesoy,a.CensusStreetName as CensusStreetName,a.Censustambon as Censustambon,a.CensusCity as CensusCity,a.CensusProvince as CensusProvince,a.CensusPostcode as CensusPostcode,a.IncomePerMonth as IncomePerMonth,a.EduLevel as EduLevel,a.AddressOccupation as AddressOccupation,a.Occupation as Occupation,a.OherIncome as OherIncome,a.OherIncomeFrom as OherIncomeFrom,b.MariageStatus as MariageStatus FROM [Family] a join r_MariageStatus b on a.MariageStatus=b.code where a.CID=@CID and a.fCID=@fCID", scon);
                cmd.Parameters.AddWithValue("@CID", CIDstring);
                cmd.Parameters.AddWithValue("@fCID", fCIDstring);
                scon.Open();
                SqlDataReader reader2 = cmd.ExecuteReader();


                if (reader2.Read())
                {
                    Name.Text = reader2["Name"].ToString();
                    LastName.Text = reader2["LastName"].ToString();
                    CID.Text = reader2["fCID"].ToString();
                    LiveStatus.Text = reader2["LiveStatus"].ToString();
                    Race.Text = reader2["Race"].ToString();
                    Religion.Text = reader2["Religion"].ToString();
                    LiveHouseNumber.Text = reader2["LiveHouseNumber"].ToString();
                    LiveHouseName.Text = reader2["LiveHouseName"].ToString();
                    LiveHouseMoo.Text = reader2["LiveHouseMoo"].ToString();
                    LiveHousesoy.Text = reader2["LiveHousesoy"].ToString();
                    Livetambon.Text = reader2["Livetambon"].ToString();
                    LiveCity.Text = reader2["LiveCity"].ToString();
                    LiveProvince.Text = reader2["LiveProvince"].ToString();
                    LivePostcode.Text = reader2["LivePostcode"].ToString();
                    CensusHouseNumber.Text = reader2["CensusHouseNumber"].ToString();
                    CensusHouseName.Text = reader2["CensusHouseName"].ToString();
                    CensusHouseMoo.Text = reader2["CensusHouseMoo"].ToString();
                    CensusHousesoy.Text = reader2["CensusHousesoy"].ToString();
                    Censustambon.Text = reader2["Censustambon"].ToString();
                    CensusCity.Text = reader2["CensusCity"].ToString();
                    CensusProvince.Text = reader2["CensusProvince"].ToString();
                    CensusPostcode.Text = reader2["CensusPostcode"].ToString();
                    IncomePerMonth.Text = reader2["IncomePerMonth"].ToString();
                    OherIncome.Text = reader2["OherIncome"].ToString();
                    OherIncomeFrom.Text = reader2["OherIncomeFrom"].ToString();
                    EduLevel.Text = reader2["EduLevel"].ToString();
                    Occupation.Text = reader2["Occupation"].ToString();
                    MariageStatus.Text = reader2["MariageStatus"].ToString();
                    AddressOccupation.Text = reader2["AddressOccupation"].ToString();
                    LastNation.Text = reader2["Nation"].ToString();
                    CensusStreetName.Text = reader2["CensusStreetName"].ToString();
                    LiveStreetName.Text = reader2["LiveStreetName"].ToString();
                }
                else
                {

                }
                scon.Close();
                reader2.Close();
            }
        }















        protected void edit_Click(object sender, EventArgs e)
        {
            sendsession2();
        }

        protected void sendsession2()
        {
            Session["fCID"] = CID.Text;



            Response.Redirect("~/familyedit.aspx");


        }

       
    }
}